package com.zx.inf.sys.conf;

import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

public class DataSourceContextHolder {
    private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();
    private static final Map<String, DataSource> dataSourceMap = new HashMap<>();

    public static void setDataSourceType(String dataSourceType) {
        contextHolder.set(dataSourceType);
    }

    public static String getDataSourceType() {
        return contextHolder.get();
    }

    public static void clearDataSourceType() {
        contextHolder.remove();
    }

    public static void addDataSource(String id, HikariDataSource dataSource) {
        dataSourceMap.put(id, dataSource);
    }

    public static DataSource getDataSource(String dsId) {
        return dataSourceMap.get(dsId);
    }
}
